import { legacy_createStore as createStore, combineReducers, applyMiddleware } from 'redux'
import logger from 'redux-logger'
import carReducer from './car/car'
import historyReducer from './history/history'
const rootReducer = combineReducers({
	carReducer,
	historyReducer
})

export type RootState = ReturnType<typeof rootReducer>

const store = createStore(rootReducer, applyMiddleware(logger))

// 订阅仓库
store.subscribe(() => {
	const state = store.getState()
	localStorage.setItem('car', JSON.stringify(state.carReducer.car))
})

export default store